package com.yztc.youbadbad.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yztc.youbadbad.R;
import com.yztc.youbadbad.bean.homepage.ProductBean;
import com.yztc.youbadbad.helper.RecyclerViewAdapterHelper;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 专场列表里的面商品
 * Created by Tiffany.V.Chou on 2016/11/16.
 */

public class ProdectRecyclerAdapter extends RecyclerViewAdapterHelper<ProductBean> {
    private IProdectClickListener iProdectClickListener;
    private int position;

    public interface IProdectClickListener{
        void producetItemclicked(int position1, int index2);
    }

    public ProdectRecyclerAdapter(Context context, List<ProductBean> list,
                                  IProdectClickListener iProdectClickListener,
                                  int position) {
        super(context, list);
        this.iProdectClickListener = iProdectClickListener;
        this.position = position;
    }

    @Override
    public RecyclerView.ViewHolder onCreateMyViewHolder(ViewGroup parent, int viewType) {
        View itemView = mInflater.inflate(R.layout.item_eventproduct, null);
        return new ViewHolder(itemView);
    }

    @Override
    public void onBindMyViewHolder(RecyclerView.ViewHolder holder, final int index) {
        ProductBean bean = mList.get(index);
        ((ViewHolder)holder).brandNameTv.setText(bean.getBrand_name());
        ((ViewHolder)holder).storePriceTv.setText(bean.getStore_price()+"");
        ((ViewHolder)holder).nameTv.setText(bean.getName());
        if (bean.getActivity_icon() != null){
            Glide.with(mContext).
                    load(bean.getActivity_icon().get(0).getUrl()).
                    into(((ViewHolder)holder).activityIconIv);
        }

        Glide.with(mContext).load(bean.getProduct_image()).into(((ViewHolder)holder).productImageIv);
        ((ViewHolder)holder).itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                iProdectClickListener.producetItemclicked(position,index);
            }
        });

    }


    static class ViewHolder extends RecyclerView.ViewHolder{
        @BindView(R.id.product_image_iv)
        ImageView productImageIv;
        @BindView(R.id.activity_icon_iv)
        ImageView activityIconIv;
        @BindView(R.id.brand_name_tv)
        TextView brandNameTv;
        @BindView(R.id.name_tv)
        TextView nameTv;
        @BindView(R.id.store_price_tv)
        TextView storePriceTv;


        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
